#include "stdafx.h"
#include "FdoCMSConnectionImp.h"
#include "FdoCMSGoogleConnectionImp.h"
#include "FdoCMSBingConnectionImp.h"
#include "FdoCMSYahooConnectionImp.h"
#include "FdoCMSXmlGlobals.h"
#include "FdoCMSGlobals.h"

FdoCMSConnectionImp::FdoCMSConnectionImp(void)
{
}

FdoCMSConnectionImp::~FdoCMSConnectionImp(void)
{
}

// ClassName represents the maptype
FdoString* FdoCMSConnectionImp::GetClassName()
{
    if(m_clsName == NULL)
        // Bing's map type is hard to read and
        // Yahoo's map type is defined by its url server not by parameter, so uses google's name as class name totally
        m_clsName = FdoCMSGlobals::MapFormat_Google_roadmap;   

    return m_clsName;
}


void FdoCMSConnectionImp::SetClassName(FdoString* name)
{
    
     // SplitFeatureClassName(,m_clsName);
    if(!name)
    {
        m_clsName = L"";
        return;
    }

     std::wstring fullName = name;
     size_t startPos = fullName.find(L":");
     if(startPos != std::wstring::npos)
         m_clsName = fullName.substr(startPos+1).c_str();
     else
         m_clsName = name;
}

FdoString* FdoCMSConnectionImp::GetMapType()
{
    return GetClassName();
}

FdoCMSConnectionImp* FdoCMSConnectionImpFactory::Create(const FdoString* serviceUrl)
{
    if(0 == FdoCommonStringUtil::StringCompareNoCase(serviceUrl, FdoCMSXmlGlobals::CMSGoogleServiceName))
    {
        return new FdoCMSGoogleConnectionImp();
    }
    else if(0 == FdoCommonStringUtil::StringCompareNoCase(serviceUrl, FdoCMSXmlGlobals::CMSBingServiceName))
    {
        return new FdoCMSBingConnectionImp();
    }
    else if(0 == FdoCommonStringUtil::StringCompareNoCase(serviceUrl, FdoCMSXmlGlobals::CMSYahooServiceName))
    {
        return new FdoCMSYahooConnectionImp();
    }
    else
        return NULL;
}
